<template>
  <view class="member">
    <view class="form">
      <u--form
        labelPosition="top"
        labelWidth="200rpx"
        :model="form"
        ref="uForm"
        :rules="rules"
      >
        <u-form-item required  label="授权人姓名" borderBottom prop="contact">
          <u--input
            placeholder="请输入"
            v-model="form.contact"
            border="none"
			maxlength="6"
          ></u--input>
        </u-form-item>
        <u-form-item required label="授权人手机号" prop="phone" >
          <u--input
            placeholder="请输入"
            v-model="form.phone"
            border="none"
          ></u--input>
        </u-form-item>
	   </u--form>
    </view>
    <view class="submit flex-c" @click="submit">确认</view>
  </view>
</template>

<script>
import Upload from "@/components/Upload";
import { addAuthorizer } from "@/api";
export default {
  components: {
    Upload,
  },
  data() {
    return {
      form: {
        contact: null,
        phone: null,
		parentId:null,
		deptId:null,
      },
      rules: {
		  contact: [
		  	{
		  	 type: 'string',
		  	  required: true,
		  	  message: "请输入姓名",
		  	  trigger: ["blur"],
		  	},
		  	{ pattern: /^[\u4e00-\u9fa5]+$/, message: '姓名必须为中文',trigger: 'blur' }	
		  ],
	   phone: [
		{
		  required: true,
		  message: "请输入授权人手机号",
		  trigger: ["blur"],
		},
		{
			validator: (rule, value, callback) => {
				console.log(value);
				// 返回true表示校验通过，返回false表示不通过
				// uni.$u.test.mobile()就是返回true或者false的
				return uni.$u.test.mobile(value);
			},
			message: '手机号码不正确',
			trigger: ['blur'],
		}
	   ]
      },
    };
  },
  onReady() {
  	this.$refs.uForm.setRules(this.rules)
  },
  methods: {
    submit() {
		let userInfo = wx.getStorageSync('userInfo')
		this.form.parentId = userInfo.phonenumber
		this.form.deptId = uni.getStorageSync('deptId'),
      this.$refs.uForm.validate().then((res) => {
        addAuthorizer(this.form).then((res) => {
          this.$toast("添加成功");
          this.$route({
            type: "back",
            isDelay: true,
          });
        });
      });
    },
  },
};
</script>

<style lang="less" scoped>
.member {
  padding:30rpx;
  .active {
    background: #f7f7f7;
    border: 2rpx solid #138e57;
    color: #138e57;
  }
  .title {
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    font-size: 40rpx;
    color: #000000;
    padding: 48rpx 0 26rpx 0;
	text-align: center;
  }
  .form {
    background: #ffffff;
    border-radius: 16rpx;
    padding: 0 30rpx;
    .six {
      view {
        padding: 12rpx 60rpx;
        background: #f7f7f7;
        border-radius: 200rpx;
        margin: 0 12rpx;
      }
    }
  }
  .submit {
    background: linear-gradient(83deg, #48b453 0%, #2c9f79 100%);
    border-radius: 200rpx;
    font-size: 32rpx;
    color: #ffffff;
    padding: 26rpx;
    margin: 60rpx 40rpx 0 40rpx;
  }
}
</style>
